import Axios from '../../lib/request'
import axios from 'axios'

//获取客户列表
export const getCustomerList = function (data) {
    return Axios.post('/tbCustomer/list', data)
}

//获取当前客户信息
const getCustomerDetailById = function (data) {
    return Axios.get('/tbCustomer/queryDetails', { params: data })
}

//获取当前客户所有收货地址
const getCustomerAddressById = function (data) {
    return Axios.get(`/tbCustomeraddress/getAddress`, { params: { customerId: data.id } })
}

//获取客户所有订单
const getCustomerOrderList = function (id) {
    return Axios.get(`/getAddress/${id}`)
}
//通过客户Id查询是否申请过代理
export const getCustomerisAgent = function (id) {
    return Axios.get(`/agent/isAgent?customerId=${id}`)
}

export const getCustomerDetail = function (data) {
    return new Promise(function (reslove, reject) {
        axios.all([getCustomerDetailById(data), getCustomerAddressById(data)])
            .then(axios.spread(function (res1, res2) {
                reslove({ res1, res2 })
            })).catch(err => {
                reject(err)
            })
    })
}

export const bindDelegete = function (data) {
    return Axios.post('/agent/add', data)
}